﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SharpSoft.WPF
{
    public class AppHelper
    {
        static AppHelper()
        {
            var logsfolder = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "logs");
            if (!System.IO.Directory.Exists(logsfolder))
            {
                System.IO.Directory.CreateDirectory(logsfolder);
            }
            errorLogFile = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "logs", "error.log");
        }
        static readonly string errorLogFile;

        public static void WriteError(Exception ex)
        {
            using (var fs = new FileStream(errorLogFile, FileMode.Append, FileAccess.Write))
            {
                using (var sw = new StreamWriter(fs, Encoding.UTF8))
                {
                    sw.WriteLine($"----[{DateTime.Now:yyyy-MM-dd HH:mm:ss}]----------------------------------");
                    sw.WriteLine($"{ex.Message}");
                    sw.WriteLine($"{ex.StackTrace}");
                }
            }
        }
    }
}
